# -*- coding: utf-8 -*-
from flask import Flask, request, jsonify
import random
import json

app = Flask(__name__)


@app.route("/rnd")
def random_num():
    print(request.method)
    return str(random.randint(0, 10))


@app.route('/', methods=['POST'])
def print_messages():
    reply = {"result": "ok", "message": "success成功"}
    print("got post request: ", request.get_data())

    res = json.loads(request.get_data())
    print(res)
    # return json.dumps(reply)
    return jsonify(reply)


@app.route("/json")
def get_json():
    dict = {}
    dict['msg'] = '成功'
    dict['data'] = random.randint(100, 200)
    return json.dumps(dict, ensure_ascii=False)


if __name__ == '__main__':
    # app.run(port=8000)
    app.config['JSON_AS_ASCII'] = False
    app.run(host='0.0.0.0', port=5555, debug=True)
